package com.itsu.job.rpc.request;

import cn.hutool.json.JSONUtil;
import com.itsu.job.exception.JobException;
import org.springframework.util.StringUtils;

import java.util.Map;
import java.util.function.BiFunction;

/**
 * @author Jerry.Su
 * @Date 2022/1/28 13:43
 */
public abstract class JobRpcRequestHandler implements BiFunction<String, String, Map<String, Object>> {


    protected Map<String, Object> parseParams(String requestData) {
        if (!StringUtils.hasText(requestData)) {
            throw new JobException("request parameter is null");
        }
        return JSONUtil.parseObj(requestData);
    }

    protected String getJobId(String requestData) {
        return (String) parseParams(requestData).get("jobId");
    }
}
